
package com.clps.dev.sms.service.sm.impl;
import java.util.List;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.clps.dev.sms.common.result.ResponseResult;
import com.clps.dev.sms.common.result.ResultType;
import com.clps.dev.sms.common.service.impl.BaseServiceImpl;
import com.clps.dev.sms.dao.sm.AccountDao;
import com.clps.dev.sms.entity.sm.Account;
import com.clps.dev.sms.service.sm.IAccountService;
import com.clps.dev.sms.util.result.ResponseResultUtil;

/**
 * 
 * ClassName: AccountServiceImpl 
 * @date 2018-11-27 14:18:18 
 *
 * @author jackie.duan
 * @version V1.0
 * @since JDK 1.8
 */
@Service
@Transactional
public class AccountServiceImpl extends BaseServiceImpl<Account> implements IAccountService {

	
	/**
	 * Creates a new instance of AccountServiceImpl.
	 *
	 * @param clazz
	 */
	
	public AccountServiceImpl() {
		super(Account.class);
		
	}
	@Autowired
	private AccountDao accountDao;
	/**
	 * @see com.clps.dev.sms.service.sm.IAccountService#isExistAccount(java.lang.String)
	 */
	@Override
	public ResponseResult<Account> isExistAccount(String accountName) {
		
		Account account = accountDao.queryByName(accountName);
		
		if(account != null) {
		
			return ResponseResultUtil.success(ResultType.USER_REPEAT);
		}else {
	
			return ResponseResultUtil.error(ResultType.USER_NULL);
		}
	}
	/**
	 * 
	 * @see com.clps.dev.sms.service.sm.IAccountService#queryAccountById(java.lang.Integer)
	 */
	@Override
	public ResponseResult<Account> queryAccount(Integer id) {
		
		Account account = accountDao.queryById(id);
		
		return ResponseResultUtil.success(ResultType.QUERY_SUCCESS, account);
	}
	/**
	 * 
	 * @see com.clps.dev.sms.service.sm.IAccountService#queryAccountByName(java.lang.String)
	 */
	@Override
	public ResponseResult<Account> queryAccount(String accountName) {
		
		Account account = accountDao.queryByName(accountName);
		
		if(account == null) {
			return ResponseResultUtil.error(ResultType.QUERY_FAULT);
		}else {
			return ResponseResultUtil.success(ResultType.QUERY_SUCCESS,account);
		}
	}
	

	/**
	 * 
	 * @see com.clps.dev.sms.service.sm.IAccountService#updateAccountById(com.clps.dev.sms.entity.sm.Account)
	 */
	@Override
	public ResponseResult<Account> editAccount(Account account) {
		
		if(account == null) {
		
			return ResponseResultUtil.error(ResultType.OBJECT_NULL);
		}
	
		int a = accountDao.update(account, account.getAccountId());
		if(a > 0) {
			
			return ResponseResultUtil.success(ResultType.UPDATE_SUCCESS,account);	
		}else {
			
			return ResponseResultUtil.error(ResultType.UPDATE_FAULT);
		}
	}

	/**
	 * 
	 * @see com.clps.dev.sms.service.sm.IAccountService#queryAllAccounts()
	 */
	@Override
	public ResponseResult<Account> queryAllAccounts() {
		
		List<Account> list = accountDao.queryALl();
		
		return ResponseResultUtil.success(ResultType.QUERY_SUCCESS,list);
	}
	
	
	
}
